import { SceneManager } from './scene/SceneManager'

export class ThreeApp {
  private sceneManager: SceneManager
  private animationFrameId: number = 0

  constructor() {
    this.sceneManager = new SceneManager()
    this.animate = this.animate.bind(this)
  }

  public init(): void {
    // 开始动画循环
    this.animate()
  }

  private animate(): void {
    this.animationFrameId = requestAnimationFrame(this.animate)
    this.sceneManager.update()
  }

  public getRendererDomElement(): HTMLElement {
    return this.sceneManager.getRendererManager().getRenderer().domElement
  }

  public dispose(): void {
    // 清理资源
    cancelAnimationFrame(this.animationFrameId)
    this.sceneManager.dispose()
  }
}
